

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>数据库管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/html/layui/css/layui.css" media="all">
  <link rel=stylesheet href="/html/lib/code/doc/docs.css">
<link rel="stylesheet" href="/html/lib/code/lib/codemirror.css">
<link rel="stylesheet" href="/html/lib/code/addon/hint/show-hint.css">
  <style >
  .layui-form-item .layui-input-inline {
    width:500px;
    }
     .layui-textarea {
    	height:200px;
    }
    .CodeMirror {
	border-top: 1px solid #888;
	border-bottom: 1px solid #888;
	height: 100%;
}
  </style>
</head>
<body>

  <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
      
    <div class="layui-form-item">
      <label class="layui-form-label">catalog</label>
      <div class="layui-input-inline">
        <input type="text"  name="catalog" id="catalog" value="xmlcore" placeholder="请输入catalog"  autocomplete="off" class="layui-input"/>
      </div>
    </div>
  	  <div class="layui-form-item">
      <label class="layui-form-label">数据库</label>
      <div class="layui-input-inline">
        <input type="text"  name="schemaPattern" id="schemaPattern" value="xmlcore" placeholder="请输入数据库"  autocomplete="off" class="layui-input"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">表</label>
      <div class="layui-input-inline">
        <input type="text"  name="tableNamePattern" id="tableNamePattern" value="" placeholder="请输入数据库"  autocomplete="off" class="layui-input"/>
      </div>
    </div>
  	  <div class="layui-form-item">
      <label class="layui-form-label">当前页</label>
      <div class="layui-input-inline">
        <input type="text"  name="page" id="page" value="1" placeholder="请输入当前页码"  autocomplete="off" class="layui-input"/>
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">SQL窗口</label>
      <div class="layui-input-inline">
        <textarea  name="sql" id="sql"  placeholder="请输入sql" style="height:200px;" autocomplete="off" class="layui-input"></textarea>
      </div>
    </div>
    
    <div class="layui-form-item ">
      <input type="hidden" name="limit" value="10"/>
      <input type="hidden" name="op" value="table"/>
      <label class="layui-form-label"></label>
      <div class="layui-input-inline" style="text-align:right;" >
       <input type="button" lay-submit lay-filter="layuiadmin-app-form-dbinfo" id="layuiadmin-app-form-dbinfo" value="数据库信息" class="layui-btn layui-btn-normal">
      	<input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="执行SQL" class="layui-btn layui-btn-normal">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-query" id="layuiadmin-app-form-query" value="查询SQL" class="layui-btn layui-btn-normal">
      </div>
      
    </div>
    <div class="layui-form-item ">
      <label class="layui-form-label">请求结果</label>
      <div class="layui-input-inline">
      	<textarea  name="result" id="result" style="height:200px;"  autocomplete="off" class="layui-input"></textarea>
      </div>
    </div>
    
  </div>

  <script src="/html/layui/layui.js"></script>  
  <script src="/html/lib/xmselect/xm-select.js"></script>  
  <script src="/html/lib/mock/mock.js"></script> 
  <script src="/html/lib/code/lib/codemirror.js"></script>
	<script src="/html/lib/code/addon/hint/show-hint.js"></script>
	<script src="/html/lib/code/addon/hint/xml-hint.js"></script>
	<script src="/html/lib/code/addon/hint/html-hint.js"></script>
	<script src="/html/lib/code/mode/xml/xml.js"></script>
	<script src="/html/lib/code/mode/javascript/javascript.js"></script>
  <script>
  layui.config({
    base: '/html/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,form = layui.form;
    var dataEditor =null
    var resultEditor=null
    
   
   form.on('submit(layuiadmin-app-form-dbinfo)', function(data){
		exeSql(data,'dbinfo')
   });
   form.on('submit(layuiadmin-app-form-query)', function(data){
		exeSql(data,'query')
   });
    //监听提交
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      exeSql(data,'exe')
    });
    function exeSql(data,type){
      var path="/api/db/sql/query"
      if(type=='exe'){
     	 path="/api/db/sql/exe"
      }else if(type=='dbinfo'){
      	path="/api/db/sql/dbinfo"
      }
    	if(resultEditor){
      	resultEditor.setValue("")
      }
      var field = data.field; //获取提交的字段
      
      //header
		$.ajax({
			async : true,
			"url" : path,
			"global" : false,
			"type" : "post",
			"contentType": "application/x-www-form-urlencoded",
			"dataType" : "json",
			"timeout" : "60000",
			"data" : field,
			"traditional":true,
			"success" : function(a,b,c){
           var data=JSON.stringify(a,null,2);
           var mode={name: "javascript", json: true}
           if(!resultEditor){
               resultEditor =CodeMirror.fromTextArea(document.getElementById("result"), {
               lineNumbers : true,
               lineWrapping : true,
               mode : mode,
               extraKeys : {
                 "Alt-/" : "autocomplete"
               }
               //,value: document.documentElement.innerHTML
             });
           }
          
           resultEditor.setValue(data)
				//$("#result").val(data)
			},
			"error" : function(err, msg, code) {
				return false;
			}
		});
    }
  })
  </script>
</body>
</html>
